home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #14 / Monster Media No. 14 (April 1996) (Monster Media, Inc.).ISO / os2 / mlrxshl.zip / LESS.CMD < prev    next >
OS/2 REXX Batch file  |  1995-11-16  |  2KB  |  62 lines

  1. /* less.cmd 951116 */
  2. trace off; call on error; '@echo off'
  3.  
  4. call RxFuncAdd 'SysLoadFuncs','RexxUtil','SysLoadFuncs'
  5. call SysLoadFuncs
  6. parse value SysTextScreenSize() 1 1 1 1 'stdin: = <>' '08'x '0d'x arg() arg(1) with r c m d l n t.1 E H B G f A
  7.  
  8. if f then m = 0
  9. do _ = 1 to words(A)
  10.    call SysFileTree word(A,_),p,OF; do z = 1 to p.0; m = m+1; t.m = p.z; end; 
  11. end
  12. if m = 0 then do; say SysGetMessage(2); exit 1; end
  13.  
  14. main:
  15. file = t.n; call seek l
  16. signal on syntax
  17. do forever
  18.    if \ in(E||G) then do; call SysCurPos 0,0; do r-1; call emit; end; end
  19.    if \ in(E) then call out ':'word(EOF,1+lines(file))
  20.  
  21.    key = SysGetKey(); if in('00E0'x) then key = translate(SysGetKey(NOECHO),B'1b'x' NP'H,'I=QåàKM')
  22.    select
  23.       when in(E) then call out B'    <'file' line='l' col='d' pos='exc(SEEK)'/'exc(QUERY SIZE)' file 'n' of 'm'>'
  24.       when in(' ') then l = l+r-1
  25.       when in(B'.') then call seek l-(r-1)*(key = B)
  26.       when in('/') then do; call exc CLOSE; s = cmdin(); if s = '' then i = i+1; else do; call SysFileSearch s,file,p.,'n'; i = 1; end; call seek word(p.i,1); end
  27.       when in(H) then do; d = max(1,d+20*(c2d(key)-61)); call seek l; end
  28.       when in(NP) then do; call exc CLOSE; d = 1; l = 1; n = max(1,min(m,n+79-c2d(key))); signal main; end
  29.       when in(G) then do; call emit; l = l+1; end
  30.       when in('1b'x) then do; call out; call SysCurPos r-2,0; exit; end
  31.       when in(123456789) then call seek cmdin(key)
  32.       when in('+-') then call seek l+cmdin(key)
  33.    otherwise
  34.       interpret cmdin(key); key = G
  35.    end
  36. end
  37.  
  38. in:
  39.    return pos(key,arg(1)) > 0
  40.  
  41. exc:
  42.    return stream(file,'c',arg(1))
  43.  
  44. cmdin:
  45.    return arg(1)linein('con:')
  46.  
  47. out:
  48.    call charout ,left(arg(1),c-3)
  49.    return SysCurPos(r-1,1)
  50.  
  51. emit:
  52.    return charout(,left(substr(translate(linein(file),' ■·',B'0709'x),d),c))
  53.  
  54. seek:
  55.    if f then do; l = max(arg(1),1); call linein file,1,0; do l-1; call linein file; end; end
  56. error:
  57.    return
  58.  
  59. syntax:
  60.    key = E; call charout ,':'
  61.    signal main
  62.